#include "initSDL.h"
#include <GL/glew.h>

SDL_Window * InitSDLWindow(const char * title, uint32_t width, uint32_t height) {
    SDL_Window *win =
        SDL_CreateWindow(title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
                         width, height, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN);
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
    SDL_GLContext * gl = SDL_GL_CreateContext(win);
    SDL_GL_MakeCurrent(win, gl);
    GLenum err = glewInit();
    if(err != GLEW_OK) {
        const char * msg = (const char *)glewGetErrorString(err);
        puts(msg);
        exit(-1);
    }
    SDL_GL_SetSwapInterval(1);
    printf("gl version: %s\ngl render: %s\n", glGetString(GL_VERSION), glGetString(GL_RENDERER));
    return win;
}
